<?php
/**
 * 门店管理端的活动管理（整理Activity.php代码）
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-03-28
 * Time: 下午 11:26
 */
namespace App;
use Model\ActivityMod;
use Pub\date\Date;

class ActivityS extends Action
{
	private $Activity = null;  //活动

	public function __construct()
	{
		parent::__construct();
		$this->Activity = new ActivityMod();
	}

    /**
     * 获取门店管理端的活动列表
     * @param limit  [0,10] 获取列表下标数量
     */
	public function getList()
    {
        $_search = array();
        if(isset($this->_gpc['search_keyword'])){
            $_search = array(
                'search_keyword'=>$this->_gpc['search_keyword'],
                'search_type'=>$this->_gpc['search_type']
            );
        }
        $_list = $this->Activity->storeList($this->_gpc['limit'],$_search);
        if(count($_list) > 0){
            foreach($_list as $_k=>$_v){
                $_list[$_k]['status'] = Date::time2time($_v['start'],$_v['end']);
                $_list[$_k]['cover'] = tomedia($_v['cover']);
                $_list[$_k]['start_time'] = date('Y-m-d H:i',$_v['start']);
                $_list[$_k]['end_time'] = date('Y-m-d H:i',$_v['end']);
            }
            $this->_result = array('status'=>'success','data'=>$_list);
        }
        $this->result($this->_result);
    }

    /**
     * 获取一条活动数据
     * @param activity_id 活动id
     * @param return 返回字段
     */
    public function getOne()
    {
        $_one = $this->Activity->findOne(array('id'=>$this->_gpc['activity_id'],'status !='=>9,'end >'=>TIMESTAMP),$this->_gpc['return']);
        if($_one){
            $this->_result = array('status'=>'success','data'=>$_one);
        }
        $this->result($this->_result);
    }

}